/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assisisw.smartcal.entitysubsystem;

import assisisw.smartcal.persistencesubsystem.IDAOProvider;
import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

/**
 *
 * @author Francesco
 */
@Stateless ()
@TransactionManagement ( value = TransactionManagementType.CONTAINER)
public class NotificationController implements INotificationController 
{

    // Instance Fields
    
    @EJB ()
    private IDAOProvider daoProvider ;
 
    // Instance Methods
    
    /***/
    public NotificationController () {}

    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public Notification insert ( Notification.NotificationType type, Event generatingEvent, User recipient , String message ) 
    {
        Notification newNot ;
        newNot = new Notification ( new Date () , type, generatingEvent, recipient , message ) ;
        daoProvider.getNotificationDAO ().insert ( newNot ) ;
        return newNot ;
    }
    
    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public void markAsRead ( Notification notification ) 
    {
        notification.setAlreadyRead(true); 
        daoProvider.getNotificationDAO().update(notification); 
    }
    
}
